﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using RaisingStudio.Xna.Graphics;

namespace WindowsGame1
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game7 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        DrawingBatch drawingBatch;


        public Game7()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            drawingBatch = new DrawingBatch(GraphicsDevice);
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // TODO: Add your update logic here

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.White);

            // TODO: Add your drawing code here
                    PresentationParameters pp = GraphicsDevice.PresentationParameters;
            int bufferWidth = pp.BackBufferWidth;
            int bufferHeight = pp.BackBufferHeight;
    Texture2D texture = new Texture2D(GraphicsDevice, bufferWidth, bufferHeight);
    TextureContext tc = new TextureContext(texture);

    tc.Begin();
    //tc.DrawLine(10, 20, 100, 20, Color.Red);
    //tc.DrawRectangle(120, 10, 100, 20, Color.Blue);
    //tc.DrawTriangle(240, 10, 240, 60, 200, 60, Color.Black);
    //tc.DrawEllipse(310, 10, 50, 50, Color.Green);
    //tc.DrawPolyline(new Vector2[] { new Vector2(410, 10), new Vector2(440, 10), new Vector2(420, 20), new Vector2(440, 40), new Vector2(410, 60) }, Color.Aqua);
    //tc.DrawFilledRectangle(120, 110, 150, 110, Color.Blue);

    //tc.DrawFilledRectangle(120, 310, 100, 110, Color.Blue);
    //tc.DrawFilledRectangle(320, 310, 100, 110, Color.Blue);
    //tc.DrawFilledRectangle(423, 310, 101, 111, Color.Blue);
    //tc.DrawFilledRectangle(527, 311, 101, 110, Color.Blue);

//           tc. ProcessDrawFilledRectangle: {X:632 Y:133}, {X:72 Y:165}
//ProcessDrawFilledRectangle: {X:468 Y:113}, {X:61 Y:355}
//ProcessDrawFilledRectangle: {X:259 Y:84}, {X:574 Y:219}
//            ProcessDrawFilledRectangle(new Vector2() {X:40 Y:389}, new Vector2() {X:6 Y:129}, Color.Black)
//ProcessDrawFilledRectangle(new Vector2() {X:265 Y:195}, new Vector2() {X:11 Y:130}, Color.Black)
//ProcessDrawFilledRectangle(new Vector2() {X:355 Y:402}, new Vector2() {X:254 Y:275}, Color.Black)
//ProcessDrawFilledRectangle(new Vector2() {X:751 Y:151}, new Vector2() {X:133 Y:189}, Color.Black)
//ProcessDrawFilledRectangle(new Vector2() {X:737 Y:180}, new Vector2() {X:514 Y:9}, Color.Black)
//ProcessDrawFilledRectangle(new Vector2() {X:356 Y:50}, new Vector2() {X:572 Y:204}, Color.Black)
//ProcessDrawFilledRectangle(new Vector2() {X:501 Y:477}, new Vector2() {X:649 Y:79}, Color.Black)
//ProcessDrawFilledRectangle(new Vector2() {X:779 Y:355}, new Vector2() {X:720 Y:256}, Color.Black)
//ProcessDrawFilledRectangle(new Vector2() {X:15 Y:14}, new Vector2() {X:580 Y:367}, Color.Black)
//ProcessDrawFilledRectangle(new Vector2() {X:324 Y:43}, new Vector2() {X:762 Y:409}, Color.Black)
//ProcessDrawFilledRectangle(new Vector2() {X:117 Y:98}, new Vector2() {X:328 Y:36}, Color.Black)

    //tc.DrawFilledRectangle(new Vector2(10, 10), new Vector2(52, 130), Color.Blue);

    tc.DrawFilledTriangle(new Vector2(625, 326), new Vector2(467, 379), new Vector2(127, 381), Color.Blue);
    //tc.DrawFilledTriangle(new Vector2(540, 194), new Vector2(782, 131), new Vector2(669, 36), Color.Blue);

    //tc.DrawFilledRectangle(new Vector2(60, 20), new Vector2(42, 163), Color.Blue);
    //tc.DrawFilledRectangle(new Vector2(100, 20), new Vector2(52, 164), Color.Blue);
    //tc.DrawFilledRectangle(new Vector2(200, 20), new Vector2(52, 165), Color.Blue);
    //tc.DrawFilledRectangle(new Vector2(300, 20), new Vector2(42, 166), Color.Blue);
    //tc.DrawFilledRectangle(new Vector2(370, 20), new Vector2(52, 173), Color.Blue);

    //int count = 100;
    //for (int i = 0; i < count; i++)
    //{
    //    tc.DrawFilledRectangle(640 + i, 301, i, i + 1, new Color(i, i, i));

    //    tc.DrawFilledTriangle(240 + i, 110, 240, 160 + i, 200, 160, Color.Brown);
    //    tc.DrawFilledTriangle(240, 110 + i, 240, 160, 200, 160, Color.Brown);
    //}


    //tc.DrawFilledTriangle(240, 110, 240, 160, 200, 160, Color.Brown);
    //tc.DrawFilledTriangle(240, 110, 240, 160, 200, 160, Color.Brown);
    //tc.DrawFilledEllipse(310, 110, 80, 40, Color.Green);
    tc.End();

    spriteBatch.Begin();
    spriteBatch.Draw(texture, Vector2.Zero, Color.White);
    spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}
